﻿using System;
using System.Windows.Input;

namespace Microsoft.Windows.UserControls.Core.Commands
{
    public static class WizardCommands
    {
        readonly static RoutedUICommand[] commands;
        
        public static ICommand Help
        {
            get
            {
                return GetCommandByType(WizardButton.ButtonCommandType.Help);
            }
        }

        public static ICommand Previous
        {
            get
            {
                return GetCommandByType(WizardButton.ButtonCommandType.Previous);
            }
        }

        public static ICommand Next
        {
            get
            {
                return GetCommandByType(WizardButton.ButtonCommandType.Next);
            }
        }

        public static ICommand Cancel
        {
            get
            {
                return GetCommandByType(WizardButton.ButtonCommandType.Cancel);
            }
        }

        public static ICommand Finish
        {
            get
            {
                return GetCommandByType(WizardButton.ButtonCommandType.Finish);
            }
        }

        static WizardCommands()
        {
            commands = new RoutedUICommand[Enum.GetNames(typeof(WizardButton.ButtonCommandType)).Length];
        }

        static RoutedUICommand GetCommandByType(WizardButton.ButtonCommandType commandType)
        {
            if (commandType == WizardButton.ButtonCommandType.None)
                return null;

            var index = (Int32)commandType;
            lock (commands.SyncRoot)
                if (commands[index] == null)
                    commands[index] = new RoutedUICommand(GetCommandText(commandType), commandType.ToString(), typeof(WizardCommands));
            return commands[index];
        }

        static string GetCommandText(WizardButton.ButtonCommandType commandType)
        {
            switch (commandType)
            {
                case WizardButton.ButtonCommandType.Next:
                    return "Move to next";
                case WizardButton.ButtonCommandType.Previous:
                    return "Move to previous";
                case WizardButton.ButtonCommandType.Cancel:
                    return "Cancel";
                case WizardButton.ButtonCommandType.Finish:
                    return "Finish";
                case WizardButton.ButtonCommandType.Help:
                    return "Help";
                default:
                    return String.Empty;
            }
        }
    }
}